package com.haiertvbic.tvnow.protocol;

public class ConnectManager {

	public static String LOCAL_HOST = "127.0.0.1";

	public static int PORT = 7204; //得到频道列表的端口
	public static final int SERVICE_HOST_PORT = 7888;//换台的端口号，dtv和机顶盒都可以用
	
	// 发送频道的消息id
	public static final int CMD_CAE_APP_GET_AUDIO_RATE = 40060;
	public static final int CMD_CAE_APP_GET_AUDIO_RATE_RE = 40061;
	// 获取频道信息的返回码
	/*
	 * 400 6 000 成功 400 6 001 成功 ， 但是数据库 没有请求个数那 么多的频道 ， 正常 情况很少出现 400 6 002
	 * 数据库不存在或 丢失 400 6 003 操作数据库发生 错误 400 6 004 未知错误，此种 情况下 UI 可以
	 */
	public static final int SUC = 4006000;

	/**
	 * 换台
	 */
	public static final int CMD_VD_REQ_CURRENT_SIG_SOURCE = 40016;//和机顶盒相关
	public static final int CMD_VD_REQ_CURRENT_SIG_SOURCE_RE = 40017;//和机顶盒相关
	public static final int CMD_SMART_TV_ASK_LOCAL_ID_BY_COUNTRY_ID = 40084;//和dtv相关
	public static final int CMD_SMART_TV_ASK_LOCAL_ID_BY_COUNTRY_ID_RE = 40085;//和dtv相关
	// 换台相关，选择电视机
	public static final int CONNECT_DEVICE_OTHER = 3;
	// 发送换台信息时，电视机时的请求头标识
	public static final int CMD_SENT_CHANNEL_INFO = 40044;
	// 电视换台后的返回头标识
	public static final int CMD_SENT_CHANNEL_INFO_RE = 40045;
	// 换台之后的状态码
	public static final int CHANGE_CHANNEL_SUCCESS = 4004500; // 换台成功
	public static final int CHANGE_CHANNEL_FAIL = 4004501; // 换台失败：此频道不存在;
	public static final int CHANGE_CHANNEL_NOCRB = 4004502;// CRB未插入，或者CRB故障，提示用户插入或者重新插拔CRB
	public static final int CHANGE_CHANNEL_NOREMOUTESETTING = 4004503;// 未设置CRB
	/**
	 * 本地码
	 */
	// 获取本地码的请求
	public static final int CMD_CAE_APP_GET_LOCAL_CODE = 40062;
	public static final int CMD_CAE_APP_GET_LOCAL_CODE_RE = 40063;
	// 获取设备地域信息的状态码
	public static final int LOC_SUC = 4006300;
	public static final int LOC_FAIL = 4006301;

	public static final byte[] intToByte(int i) {
		byte[] abyte0 = new byte[4];
		abyte0[3] = (byte) (0xff & i);
		abyte0[2] = (byte) ((0xff00 & i) >> 8);
		abyte0[1] = (byte) ((0xff0000 & i) >> 16);
		abyte0[0] = (byte) ((0xff000000 & i) >> 24);
		return abyte0;
	}

	public static final int bytesToInt(byte[] bytes) {
		int addr = bytes[0] & 0xFF;
		addr |= ((bytes[1] << 8) & 0xFF00);
		addr |= ((bytes[2] << 16) & 0xFF0000);
		addr |= ((bytes[3] << 24) & 0xFF000000);
		return addr;
	}

	/**
	 * 将字符型转换为字节数组型
	 */
	public static byte[] charToByte(char timeType) {
		// TODO Auto-generated method stub
		byte[] tempByte = String.valueOf(timeType).getBytes();
		return tempByte;
	}

	/**
	 * short到字节数组的转换
	 * 
	 * @param s
	 * @return
	 */
	public static byte[] shortToByte(short number) {
		int temp = number;
		byte[] b = new byte[2];
		for (int i = b.length - 1; i >= 0; i--) {
			b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位
			temp = temp >> 8; // 向右移8位
		}
		return b;
	}

	public static short bytesToShort(byte[] bytesShort) {
		short sRet = 0;
		sRet += (bytesShort[0] & 0xFF) << 8;
		sRet += bytesShort[1] & 0xFF;
		return sRet;
	}
}
